<template>
  <view class="header">
    <u-navbar :border-bottom="false" title="设置	" title-size="32" title-width="500"></u-navbar>
    <view class="card">
      <view class="info">
        <view class="flex flex-jc-sb main" @click="info()">
          <view>个人信息</view>
          <view>
            <u-icon name="arrow-right" color="#999999"></u-icon>
          </view>
        </view>
        <view class="flex flex-jc-sb main" @click="goPage('/pages_system/securityCenter/securityCenter',1)">
          <view>安全中心</view>
          <view>
            <u-icon name="arrow-right" color="#999999"></u-icon>
          </view>
        </view>
        <!-- <view class="flex flex-jc-sb main" @click="goPage()">
					<view>法律条款与平台规则</view>
					<view>
						<u-icon name="arrow-right" color="#999999"></u-icon>
					</view>
				</view> -->
        <view class="flex flex-jc-sb" @click="isPush=true">
          <view>推送设置</view>
          <view>
            <u-icon name="arrow-right" color="#999999"></u-icon>
          </view>
        </view>
      </view>
      <view class="info flex flex-jc-sb" @click="clear">
        <view>清除缓存</view>
        <view><text style="color: #999999;">{{fileSizeString}}</text>
          <u-icon name="arrow-right" color="#999999"></u-icon>
        </view>
      </view>
      <view class="info flex flex-jc-sb" @click="goPage('/pages_system/about/about')">
        <view>关于我们</view>
        <view>
          <u-icon name="arrow-right" color="#999999"></u-icon>
        </view>
      </view>
      <view class="info flex flex-jc-sb" @click="goPage('/pages_system/solicitation/solicitation',1)">
        <view>意见征集</view>
        <view>
          <u-icon name="arrow-right" color="#999999"></u-icon>
        </view>
      </view>

    </view>
    <view class="tc" @click="tuichuclick" v-if="token">退出登录</view>
    <u-modal v-model="isShow" :show-cancel-button="true" title="" @confirm="cancellation" confirm-color="#FBD220">
      <view class="flex flex-jc-c" style="line-height: 100rpx;">你确定要清楚缓存吗？</view>
    </u-modal>
    <u-modal v-model="isPush" :show-cancel-button="false" title="" :show-confirm-button="false" confirm-color="#FBD220">
      <view style="text-align: center;font-weight: bold;">提示</view>
      <view style="line-height: 70rpx;text-align: center;margin-top: 20rpx;font-size: 28rpx;">
        <view>位置、通知、wifi、照片等</view>
        <view>权限可在“设置”中配置</view>
        <view class="comfig" @click="push">
          朕！知道了
        </view>
      </view>
    </u-modal>

    <!-- 温馨提示 -->
    <view class="uni-popup" v-if="signout">
      <view class="main">
        <view class="heades">
          温馨提示
        </view>
        <view class="jiangchuli">
          您是否确定退出
        </view>
        <view class="popup-footer flex">
          <view class="disagreeBtn" @tap="shenclick(0)">取消</view>
          <view class="fanhuishouy" @tap="shenclick(1)">确定</view>
        </view>
      </view>
    </view>
    <u-toast ref="uToast" />
  </view>
</template>

<script>
  export default {
    data() {
      return {
        isPush: false,
        isShow: false,
        AccountType: 0,
        fileSizeString: '',
        signout: false, //退出
				token:''
      }
    },
    onShow() {
			this.token = uni.getStorageSync('token')
      this.formatSize()
      uni.getStorage({
        key: 'Ztc_C_USER_INFO',
        success: data => {
          console.log(data.data)
          this.AccountType = data.data.account_Type
        }
      })
    },
    methods: {
      formatSize() {
        // #ifdef APP-PLUS
        let that = this;
        plus.cache.calculate((size) => {
          let sizeCache = parseInt(size);
          if (sizeCache == 0) {
            that.fileSizeString = "0B";
          } else if (sizeCache < 1024) {
            that.fileSizeString = sizeCache + "B";
          } else if (sizeCache < 1048576) {
            that.fileSizeString = (sizeCache / 1024).toFixed(2) + "KB";
          } else if (sizeCache < 1073741824) {
            that.fileSizeString = (sizeCache / 1048576).toFixed(2) + "MB";
          } else {
            that.fileSizeString = (sizeCache / 1073741824).toFixed(2) + "GB";
          }
          console.log(this.fileSizeString, '123123')
        });

        // #endif
      },
      clearCache() {
        // #ifdef APP-PLUS
        let that = this;
        let os = plus.os.name;
        if (os == 'Android') {
          let main = plus.android.runtimeMainActivity();
          let sdRoot = main.getCacheDir();
          let files = plus.android.invoke(sdRoot, "listFiles");
          let len = files.length;
          for (let i = 0; i < len; i++) {
            let filePath = '' + files[i]; // 没有找到合适的方法获取路径，这样写可以转成文件路径  
            plus.io.resolveLocalFileSystemURL(filePath, function(entry) {
              if (entry.isDirectory) {
                entry.removeRecursively(function(entry) { //递归删除其下的所有文件及子目录  
                  uni.showToast({
                    title: '缓存清理完成',
                    duration: 2000
                  });
                  that.formatSize(); // 重新计算缓存  
                }, function(e) {
                  console.log(e.message)
                });
              } else {
                entry.remove();
              }
            }, function(e) {
              console.log('文件路径读取失败')
            });
          }
        } else { // ios  
          plus.cache.clear(function() {
            uni.showToast({
              title: '缓存清理完成',
              duration: 2000
            });
            that.formatSize();
          });
        }
        // #endif
      },
      push() {
        this.isPush = false
      },
      //清楚缓存
      clear() {
        this.isShow = true
      },
      cancellation() {
        this.clearCache()
      },
      tuichuclick() {
        this.signout = true;
      },
      // 退出确定，取消
      shenclick(type) {
        if (type) {
          // uni.removeStorageSync('addressList')
          uni.removeStorageSync('invitationcode')
          // 登录信息-清除vuex
          this.$store.commit('setModel', null)
          //token存储-清除缓存
          uni.removeStorageSync('token')
          this.tim.logout().then(imResponse => {}).catch(imError => {})
          // 用户信息-清除缓存
          uni.setStorage({
            key: 'launchFlag',
            data: false,
          })
          //清除身份认证
          uni.setStorage({
            key: 'idcards',
            data: false,
          })
          
          uni.removeStorageSync('showmoButton')
          uni.removeStorageSync('bussinessid')
          uni.removeStorageSync('purchaseinformation')
          
          this.$store.commit('isSDKReady', false)
          uni.removeStorage({
            key: 'Ztc_C_USER_INFO',
            success: function(res) {
              uni.navigateBack({
                delta: 2
              })
            }
          })
        } else {
          this.signout = false;
        }
      },
      info() {
				if(!this.token){
					this.$u.toast('请登录！')
					this.$u.debounce(this.login, 1000)
					return false
				}
        if (this.AccountType === 0) {
          uni.navigateTo({
            url: '/pages_userModule/personalInformation/personalInformation'
          })
        } else if (this.AccountType === 2) {
          uni.navigateTo({
            url: '/pages_userModule/serviceInformation/serviceInformation'
          })
        }
      },
			login() {
			  uni.setStorage({
			    key: 'launchFlag',
			    data: false,
			  })
			  uni.navigateTo({
			    url: '/pages_logins/login/login'
			  })
			},
      goPage(url,num) {
				if(num===1){
					if(!this.token){
						this.$u.toast('请登录！')
						this.$u.debounce(this.login, 1000)
					}else{
						uni.navigateTo({
						  url: url
						})
					}
				}else{
					uni.navigateTo({
					  url: url
					})
				}
        
      },
    }
  }
</script>

<style lang="scss" scoped>
  .comfig {
    width: 468rpx;
    height: 88rpx;
    line-height: 88rpx;
    background: linear-gradient(0deg, #FBD220, #FFE23E);
    border-radius: 44rpx;
    margin: 40rpx auto;
    font-size: 30rpx;
  }

  .tc {
    width: 702rpx;
    height: 90rpx;
    background: #FFFFFF;
    box-shadow: 0px 0px 10rpx 0px rgba(0, 0, 0, 0.14);
    border-radius: 10rpx;
    line-height: 90rpx;
    text-align: center;
    position: fixed;
    bottom: 68rpx;
    color: red;
    right: 24rpx;
  }

  .header {
    background-color: rgb(246, 246, 246);
    height: 100vh;

    .info {
      margin: 20rpx auto;
      padding: 0 24rpx;
      width: 702rpx;
      line-height: 100rpx;
      background: #FFFFFF;
      box-shadow: 0px 0px 10rpx 0px rgba(0, 0, 0, 0.14);
      border-radius: 10rpx;

      .main {
        border-bottom: 2rpx solid #F6F6F6;
      }
    }
  }

  // 弹框
  .uni-popup {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    /*定义body的元素垂直居中*/
    justify-content: center;
    /*定义body的里的元素水平居中*/

    .main {
      background-color: #fff;
      border: #f00;
      border-radius: 20rpx;
      width: 600rpx;
      margin: auto;
      padding: 50rpx;

      .heades {
        text-align: center;
        font-size: 36rpx;
        font-family: PingFang SC;
        font-weight: 500;
        color: #000000;
      }

      .jiangchuli {
        line-height: 60rpx;
        font-size: 30rpx;
        font-family: PingFang SC;
        font-weight: 500;
        color: #333333;
        padding: 30rpx 0rpx;
        text-align: center;
      }

      .neirong {
        font-size: 26rpx;
        font-family: PingFang SC;
        font-weight: 500;
        color: #666666;
        line-height: 50rpx;
        margin-top: 20rpx;
      }

      .popup-footer {
        .jkhjkh {
          width: 468rpx;
          height: 88rpx;
          background: linear-gradient(0deg, #FBD220, #FFE23E);
          border-radius: 44rpx;
          margin-top: 40rpx;

          text-align: center;
          line-height: 88rpx;
          font-size: 30rpx;
          font-family: PingFang SC;
          font-weight: 500;
          color: #3D3D3D;
        }

        .disagreeBtn {
          width: 260rpx;
          height: 88rpx;
          background: #333333;
          border-radius: 44rpx 0px 0px 44rpx;

          font-size: 28rpx;
          font-family: PingFang SC;
          font-weight: 500;
          color: #FFE23E;
          text-align: center;
          line-height: 88rpx;
        }

        .fanhuishouy {
          width: 260rpx;
          height: 88rpx;
          background: linear-gradient(0deg, #FBD220, #FFE23E);
          border-radius: 0px 44rpx 44rpx 0px;

          font-size: 30rpx;
          font-family: PingFang SC;
          font-weight: 500;
          color: #333333;
          text-align: center;
          line-height: 88rpx;
        }
      }
    }
  }

  /deep/ uni-button:after {
    border: none;
  }
</style>
